﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_queryTeacher : System.Web.UI.Page
{
    db_teacher teacher = new db_teacher();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        Server.Execute("../inc/checkPurview.aspx");  // 此处用户权限验证
        if (!IsPostBack)
        {
            ddl_status.DataSource = new db_status().selectStatus().Tables[0].DefaultView;
            ddl_status.DataTextField = "statusName";
            ddl_status.DataValueField = "statusCode";
            ddl_status.DataBind();
            ddl_status.Items.Insert(0, new ListItem("所有状态", ""));

            tb_teacherId.Text = Request.QueryString["teacherId"];
            tb_name.Text = Request.QueryString["teacherName"];
            tb_about.Text = Request.QueryString["about"];
            ddl_status.SelectedValue = Request.QueryString["status"];
            btn_search_Click(sender, e);
        }
    }
    protected void btn_search_Click(object sender, EventArgs e)
    {
        string teacherId = tb_teacherId.Text;
        string teacherName = tb_name.Text;
        string about = tb_about.Text;
        string status = ddl_status.SelectedValue;
        DataSet ds = teacher.selectTeacher_search(teacherId,teacherName,about,status);
        //分页 开始 -------
        firstPage.NavigateUrl = null;
        prePage.NavigateUrl = null;
        nextPage.NavigateUrl = null;
        endPage.NavigateUrl = null;


        int CurPage;
        if (sender.GetType().Equals(new Button().GetType()))
        {
            CurPage = 1;
        }
        else
        {
            if (Request.QueryString["Page"] != null && Convert.ToInt32(Request.QueryString["Page"]) > 0)
                CurPage = Convert.ToInt32(Request.QueryString["Page"]);
            else
                CurPage = 1;
        }
        PagedDataSource ps = new PagedDataSource();
        ps.DataSource = ds.Tables[0].DefaultView;
        ps.AllowPaging = true;
        //每个页面显示的条数
        ps.PageSize = 10;
        onePage.Text = ps.PageSize.ToString();
        //求数据的总数
        allMsg.Text = ps.DataSourceCount.ToString();
        ps.CurrentPageIndex = CurPage - 1;
        //求总页
        allPages.Text = ps.PageCount.ToString();
        nowPage.Text = CurPage.ToString();
        //将数据源与控件绑定
        teacherList.DataSource = ps;
        teacherList.DataBind();

        //上一页
        if (!ps.IsFirstPage)
        {
            firstPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1&teacherId="+teacherId+"&teacherName="+teacherName+"&about="+about+"&status="+status;
            prePage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1) + "&teacherId=" + teacherId + "&teacherName=" + teacherName + "&about=" + about + "&status=" + status;
        }
        //下一页
        if (!ps.IsLastPage)
        {
            nextPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) + "&teacherId=" + teacherId + "&teacherName=" + teacherName + "&about=" + about + "&status=" + status;
            endPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(ps.PageCount) + "&teacherId=" + teacherId + "&teacherName=" + teacherName + "&about=" + about + "&status=" + status;
        }
        //分页 结束 -------
    }
}